package com.snake.demo.controller;

import com.snake.demo.entity.User;
import com.snake.demo.service.LoginService;
import com.snake.demo.utils.ResponseResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: snake_skin
 * @Date: 2024/05/18/12:43
 * @Description:
 */
@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) {
        return loginService.login(user);
    }

    @GetMapping("/user/logout")
    public ResponseResult logout() {
        return loginService.logout();
    }

    @GetMapping("hello")
    @PreAuthorize(("hasAuthority('system:test')"))
    public ResponseResult hello() {
        return new ResponseResult(200, "hello");
    }

}
